home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Games / MacGnuGo 0.5e / gnugo.src / exambord.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-27  |  1.7 KB  |  77 lines  |  [TEXT/R*ch]

  1. #include "comment.header"
  2.  
  3. #define EMPTY 0
  4. #define BLACKSTONE 2
  5.  
  6. extern unsigned char p[19][19], l[19][19];
  7. extern int MAXX, MAXY;
  8. extern int currentStone, opposingStone, whiteCaptured, blackCaptured;
  9. extern int whiteCapturedKoI, whiteCapturedKoJ, blackCapturedKoI, blackCapturedKoJ;
  10. extern void eval(int color);
  11. extern unsigned char capturedmat[19][19];
  12.  
  13. int examboard(int color)
  14.      /* examine pieces */
  15. {
  16.   int i, j, n;
  17.  
  18.   /*
  19.   for (i = 0; i < MAXX; i++)
  20.     for (j = 0; j < MAXY; j++)
  21.       if (p[i][j] > 2)
  22.     return;
  23.   */
  24.   
  25.   /* initialize piece captured */
  26.   if (color == BLACKSTONE)
  27.     {
  28.       blackCapturedKoI = -1;
  29.       blackCapturedKoJ = -1;
  30.     }
  31.   else
  32.     {
  33.       whiteCapturedKoI = -1;
  34.       whiteCapturedKoJ = -1;
  35.     }
  36.   n = 0; /* The number of captures this move for Ko purposes */
  37.   
  38.   /* find liberty of each piece */
  39.   eval(color);
  40.   
  41.   /* remove all piece of zero liberty */
  42.   for (i = 0; i < MAXX; i++)
  43.     for (j = 0; j < MAXY; j++)
  44.       if ((p[i][j] == color) && (l[i][j] == 0))
  45.     {
  46.       p[i][j] = EMPTY;
  47.       capturedmat[i][j] = color;
  48.       /* record piece captured */
  49.       if (color == BLACKSTONE)
  50.         {
  51.           blackCapturedKoI = i;
  52.           blackCapturedKoJ = j;
  53.           ++blackCaptured;
  54.         }
  55.       else
  56.         {
  57.           whiteCapturedKoI = i;
  58.           whiteCapturedKoJ = j;
  59.           ++whiteCaptured;
  60.         }
  61.       ++n;  /* increment number of captures on this move */
  62.     }
  63.   /* reset to -1 if more than one stone captured since  no Ko possible */
  64.   if ((color == BLACKSTONE) && (n > 1))
  65.     {
  66.       blackCapturedKoI = -1;
  67.       blackCapturedKoJ = -1;
  68.     }
  69.   else if ( n > 1 )
  70.     {
  71.       whiteCapturedKoI = -1;
  72.       whiteCapturedKoJ = -1;
  73.     }
  74.   return(n);
  75. }  /* end examboard */
  76.  
  77.